<?php
	if(!isset($_POST["numero"])){
		$aPseudos1 = pg_query($oSql, 'SELECT DISTINCT pseudo, edition FROM participation');
		$aPseudos2 = pg_query($oSql, 'SELECT DISTINCT pseudo, edition FROM participation');


		$aEditions = pg_query($oSql, 'SELECT edition FROM tournoi');

		$resData = pg_query($oSql, "	SELECT 	m1.nom AS nomj1, 
									m1.prenom AS prenomj1, 
									m1.pseudo AS pseudoj1, 
									m2.nom AS nomj2,
									m2.prenom AS prenomj2, 
									m2.pseudo AS pseudoj2,
									j1edition AS editionj1,
									j2edition AS editionj2, 
									duree, 
									to_char(dateheure, 'YYYY-MM-DD') AS dateheure,
									pointegerj1,
									pointegerj2,
									numero 
				    		FROM match JOIN membre AS m1 ON match.j1pseudo = m1.pseudo JOIN membre AS m2 ON match.j2pseudo = m2.pseudo 
				    		WHERE numero = " . $_GET["numero"]);

		$aRound = pg_query($oSql, "SELECT round1 FROM participation WHERE round1 = " . $_GET["numero"]);
		if(!pg_fetch_array($aRound)){
			$aRound = pg_query($oSql, "SELECT round2 FROM participation WHERE round1 = " . $_GET["numero"]);
			if(!pg_fetch_array($aRound)){
				$round = "round3";
			}
			else{
				$round = "round2";
			}
		}
		else{
			$round = "round1";
		}
	}
	else{
		list($pseudoj1, $editionj1) = split('#', $_POST["pseudoj1"]);
		list($pseudoj2, $editionj2) = split('#', $_POST["pseudoj2"]);
		pg_query($oSql,"UPDATE match SET 	j1pseudo = '" . $pseudoj1 . "', j1edition = '" . $editionj1 . "', pointegerj1 = " . $_POST["pointegerj1"] . ", 
											j2pseudo = '" . $pseudoj2 . "', j2edition = '" . $editionj2 . "', pointegerj2 = " . $_POST["pointegerj2"] . ",
											dateheure = '" . $_POST["dateheure"] . "', duree = " . $_POST["duree"] . "
						WHERE numero = " . $_POST["numero"]);
		pg_query($oSql, "UPDATE participation SET " . $_POST["round"] . " = " . $_POST["numero"] . " WHERE pseudo = '" . $pseudoj1 . "' AND edition = '" . $editionj1 . "'");
		pg_query($oSql, "UPDATE participation SET " . $_POST["round"] . " = " . $_POST["numero"] . " WHERE pseudo = '" . $pseudoj2 . "' AND edition = '" . $editionj2 . "'");
	}
?>